package com.kaifamiao.advice;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * @author lucien-ma
 * @date 2021/8/27
 * @apiNote
 */
@Aspect
public class LogAdvice {

    private String className;

    private String methodName;

    @Pointcut("execution(* com.kaifamiao.service.impl.*.*(..))")
    public void pt(){}

    @Before("pt()")
    public void before(JoinPoint joinPoint){
        className = joinPoint.getTarget().getClass().getName();
        methodName = joinPoint.getSignature().getName();
        System.out.println(className + "." + methodName + "执行前执行---before");
    }

    @AfterReturning("pt()")
    public void afterReturning(JoinPoint joinPoint) {
        System.out.println(className + "." + methodName + "正常执行后执行了---after-returning");
    }

    @AfterThrowing("pt()")
    public void afterThrowing(JoinPoint joinPoint) {
        System.out.println(className + "." + methodName + "抛出异常后执行了---after-throwing");
    }

    @After("pt()")
    public void after(JoinPoint joinPoint) {
        System.out.println(className + "." + methodName + "之后最终执行了---after");
    }
}
